<?php

namespace Model;

/**
 * 消息提示
 */
class Tips extends \Core\Model\Model {

    /**
     * 列出消息提示
     */
    public static function tipsList() {
        $page = new \Expand\Page;

        //设置为已读
        self::db('user_tips')->where('accept_user_id = :accept_user_id')->update(array('tips_status' => '1', 'noset' => array('accept_user_id' => $_SESSION['user']['user_id'])));

        $conititon = "ut.accept_user_id = :accept_user_id";
        $param = array('accept_user_id' => $_SESSION['user']['user_id']);

        $total = self::db('user_tips AS ut')->field('count(ut.user_tips_id) AS total')->join(self::$modelPrefix . 'timelog AS tl ON tl.timelog_id = ut.timelog_id')->join(self::$modelPrefix . 'user AS u ON u.user_id = ut.send_user_id')->join(self::$modelPrefix . 'timelog_comment AS tm ON tm.timelog_comment_id = ut.comment_id')->where($conititon)->find($param)['total'];
        $page->total($total);
        $page->handle();

        $list = self::db('user_tips AS ut')->field('tl.timelog_id, tl.timelog_title, u.user_id, u.user_name, u.user_head, tm.timelog_comment, ut.tips_time, ut.user_tips_id, ut.tips_type')->join(self::$modelPrefix . 'timelog AS tl ON tl.timelog_id = ut.timelog_id')->join(self::$modelPrefix . 'user AS u ON u.user_id = ut.send_user_id')->join(self::$modelPrefix . 'timelog_comment AS tm ON tm.timelog_comment_id = ut.comment_id')->where($conititon)->order('ut.user_tips_id DESC')->limit("{$page->firstRow}, {$page->listRows}")->select($param);

        $show = $page->show();

        return array('list' => $list, 'page' => $show);
    }

}
